Public Class utils
    Public Enum aUserMatrix
        cSESSION_ID = 0
        cCOMPANY_ID = 1
        cVIAKLIX_ID = 2
        cUSER_ID = 3
        cINCIDCONTEXT = 4
        cINVIDCONTEXT = 5
        cLOGINDATETIME = 6
        cLASTACTIVITY = 7
        cUSERPERMISSIONSSTRING = 8
        cTERMINAL_PIN = 9
        cTERMINAL_NAME = 10
        cTERMINAL_NUMBER = 11
        cTERMINAL_MARKET = 12

    End Enum
    

    Function SafeString(ByVal s As String) As String
        If IsNothing(s) Then
            SafeString = ""
        Else
            SafeString = Trim(s)
        End If
    End Function

    Function BoolToYN(ByVal b As Boolean) As String
        If CBool(b) Then
            BoolToYN = "Y"
        Else
            BoolToYN = "N"
        End If
    End Function

    Function YNToBool(ByVal value As String) As String
        If SafeString(value) = "Y" Then
            YNToBool = True
        Else
            YNToBool = False
        End If
    End Function

    Function CheckString(ByVal vMerchantid As String) As String

        'This function ensures strings have valid quotes around them for
        'insertion into a database.
        Dim iStringPos
        Dim iCurrentPos
        Dim sStringName

        iStringPos = 1
        iCurrentPos = 1

        sStringName = CStr(vMerchantid)

        Do While iStringPos > 0
            iStringPos = InStr(iCurrentPos, sStringName, "'")

            If iStringPos > 0 Then
                sStringName = Mid(sStringName, 1, iStringPos) & "'" & Mid(sStringName, iStringPos + 1)
                iCurrentPos = iStringPos + 2
            Else
                iCurrentPos = iCurrentPos + 1
            End If
        Loop

        CheckString = sStringName
    End Function


    'Function ScriptDetect(ByVal suspectfield As String)
    '    ' this function filters script identifiers
    '    Dim badarray As Array
    '    'Dim suspect_filtered As Array
    '    Dim i As Integer
    '    Dim good_string As String = ""
    '    badarray = Split(suspectfield, " ")
    '    'suspect_filtered = filter(filter(badarray, "<", False), ">", False)
    '    'For i = 0 To UBound(suspect_filtered)
    '    '    good_string = good_string & suspect_filtered(i) & " "
    '    'Next

    '    'ScriptDetect = good_string
    'End Function

    Function EscapeQuotes(ByVal value As String)
        EscapeQuotes = Replace(value, "'", "''")
    End Function

    'sPlatform = cstr(request.servervariables("http_user_agent"))
    'wincols = 515
    'winheight = 350

    'if instr(sPlatform,"Opera") then
    '	wincols = 490
    '	winheight = 330
    'elseif instr(sPlatform,"Mozilla/4.76") then
    '	wincols = 600
    '	winheight = 370
    'end if

    Function FilteredString(ByVal sStringName As String) As String

        'This function ensures strings have valid quotes around them for
        'insertion into a database.

        sStringName = Replace(sStringName, "'", "")

        sStringName = "'" & sStringName & "'"
        FilteredString = Trim(sStringName)

    End Function


    Function WrapURL(ByVal url, ByVal length) As String
        Dim newURL As String = ""
        Dim buffer As String = url
        Dim slashpos As Integer
        'Response.Write "this is the original url = " & url & "<br><br>"
        While Len(buffer) > length
            slashpos = InStrRev(Left(buffer, length), "/")
            If slashpos = 0 Then
                slashpos = length
            End If
            newURL = newURL & Left(buffer, slashpos) & "<br>"
            buffer = Right(buffer, Len(buffer) - slashpos)
            'Response.Write "buffer = " & buffer & "<br>"
            'Response.Write "newurl = " & newurl & "<br>"
        End While
        newURL = newURL & buffer

        WrapURL = newURL
    End Function
   
End Class
